<html>

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="TingGe Blog Agile agile JavaScript NodeJS">
  <meta name="author" content="TingGe<505253293@163.com>">
  <title>听歌实验室</title>
  <link type="image/x-icon" rel="shortcut icon" href="https://avatars3.githubusercontent.com/u/4074517?v=3&s=40" />
  <link rel="stylesheet" type="text/css" href="/lib/bootstrap/dist/css/bootstrap.min.css" media="screen">
  <link href="https://fonts.googleapis.com/css?family=Lato:300,400,700,300italic,400italic,700italic" rel="stylesheet" type="text/css">
  <link href="/css/landing-page.css" rel="stylesheet">
  <link href="/css/screenshots.css" rel="stylesheet">
  <style media="screen">
    #main {
      padding-top: 55px;
    }
  </style>
  <script type="text/javascript" src="/lib/jquery/dist/jquery.min.js"></script>
  <script type="text/javascript" src="/lib/html2canvas/dist/html2canvas.min.js"></script>
  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
  <!-- Navigation -->
  <nav class="navbar navbar-default navbar-fixed-top topnav" role="navigation">
    <div class="container topnav">
      <!-- Brand and toggle get grouped for better mobile display -->
      <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
          <span class="sr-only">Toggle navigation</span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>
        <a class="navbar-brand topnav" href="/">
          <i class="fa fa-flask icon-3x" aria-hidden="true"></i> 听歌实验室
        </a>
      </div>
      <!-- Collect the nav links, forms, and other content for toggling -->
      <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
        <ul class="nav navbar-nav navbar-right">
          <li>
            <a href="/html/js.html">JavaScript/NodeJS</a>
          </li>
          <li>
            <a href="/index.html#agile">敏捷/项目管理(Agile/PMP)</a>
          </li>
          <li>
            <a href="/html/cloud-bi.html">云商业智能(Cloud BI)</a>
          </li>
          <li>
            <a href="/html/iot.html">物联网(WoT/IoT)</a>
          </li>
          <li>
            <a href="/html/me.html">关于我</a>
          </li>
        </ul>
      </div>
      <!-- /.navbar-collapse -->
    </div>
    <!-- /.container -->
  </nav>
  <div id="main" class="container">
    <div class="row">
      <div id="article" class="col-md-9 content-container">
        <h1 id="node-js-">Node.js 解析</h1>
<blockquote>
<p>Node.js 嫁接了 JavaScript 生态和 C/C++ 性能与跨平台。</p>
</blockquote>
<h2 id="node-js">Node.js</h2>
<p><img src="../img/nodejs-libuv-libev-libeio.PNG" alt=""></p>
<h3 id="-">内部顶层组件架构概览</h3>
<p><img src="../img/nodejs-arch.png" alt=""></p>
<ul>
<li>Application/Modules(JS)：JavaScript 程序、Node.js 核心模块和第三方 JS 的 npm 模块</li>
<li>C/C++ Binding：桥接 Node.js 核心库依赖。</li>
<li>Addons：桥接自定义或第三方 C/C++ 库</li>
<li><a href="https://chromium.googlesource.com/v8/v8/">V8</a>：JavaScript 引擎</li>
<li><a href="https://github.com/libuv/libuv">libuv</a>：异步功能 C 库</li>
<li><a href="https://nodejs.org/en/docs/meta/topics/dependencies/">其他 C/C++ 组件和库</a>： <a href="http://c-ares.haxx.se/">c-ares</a>、<a href="https://www.openssl.org/">crypto (OpenSSL)</a>、<a href="https://github.com/nodejs/http-parser">http-parser</a> 、<a href="http://zlib.net/">zlib</a>，自定义 C/C++ 组件和库等</li>
</ul>
<h3 id="-">语言分布</h3>
<p>下图以 *nix 平台的 Node.js 为例：</p>
<p><img src="../img/nodejs-lang.png" alt=""></p>
<h3 id="-">运行流程</h3>
<p><img src="../img/nodejs-run.jpg" alt=""></p>
<h2 id="libuv-">libuv 设计图</h2>
<p>libuv 事件循环</p>
<p><img src="../img/libuv-eventloop.PNG" alt=""></p>
<p>默认由 4 个线程来处理不同的 I/O 。</p>
<p><img src="../img/libuv-architecture.png" alt=""></p>
<p>说明：Node.js 的事件驱动，在Linux 版中使用 <a href="http://software.schmorp.de/pkg/libev.html">libev</a> 和 <a href="http://software.schmorp.de/pkg/libeio.html">libeio</a>；在Windows 版中用的 IOCP 。</p>
<h2 id="-">参考</h2>
<ol>
<li><a href="https://segmentfault.com/a/1190000005892501">[译] Node.js 架构概览</a></li>
<li><a href="http://nodeschool.io/zh-cn">NodeSchool</a></li>
<li><a href="http://stackoverflow.com/questions/36766696/which-is-correct-node-js-architecture">Which is correct Node.js architecture?</a></li>
<li><a href="http://docs.libuv.org/">libuv docs</a></li>
<li><a href="http://blog.codingnow.com/2012/01/libuv.html">libuv 初窥</a></li>
</ol>

      </div>
      <div class="col-md-3" style="padding-top:20px;">
        <iframe src="http://githubbadge.appspot.com/tingge?a=0" style="border: 0;height: 142px;width: 200px;overflow: hidden;" frameBorder="0"></iframe>
      </div>
    </div>
  </div>
  <a id="html2canvas" title="截图下载-快照">&nbsp;</a>
  <script src="/lib/bootstrap/dist/js/bootstrap.min.js"></script>
  <script src="/js/article.js" charset="utf-8"></script>
  <!-- justice.js https://github.com/okor/justice  -->
  <script src="/lib/justice.min.js" charset="utf-8"></script>
  <!-- instantclick -->
  <script src="/lib/instantclick.js" charset="utf-8"></script>
  <script type="text/javascript" data-no-instant>
    Justice.init();
  </script>
</body>

</html>
